package org.paradise.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.paradise.dao.JiluDao;
import org.paradise.dao.VipDao;
import org.paradise.dao.VipTypeDao;
import org.paradise.dao.ViprecrdDao;
import org.paradise.pojo.Jilu;
import org.paradise.pojo.Vip;
import org.paradise.pojo.VipRecrd;
import org.paradise.pojo.VipType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.json.Json;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Vip")
public class VipController {
    @Autowired
    private VipDao vipDao; //会员呢表
    @Autowired
    private VipTypeDao vipTypeDao ;  //会员卡表
    @Autowired
    private ViprecrdDao viprecrdDao;  //会员卡记录表

    /**
     * 查看全部的会员信息
     * @param page
     * @param limit
     * @param vip
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, Vip vip) throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<Vip> pager= PageHelper.startPage(page,limit);
        List<Vip> list=vipDao.getList(vip);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        map.put("count",pager.getTotal());
        return map;
    }
    @RequestMapping("/get")
    @ResponseBody
    public Map<String,Object> get(Integer id,HttpSession session) throws Exception{
        Map<String,Object> map=new HashMap<>();
        Vip vip=vipDao.get(id);
        session.setAttribute("vip",vip);
        return map;
     }
    @RequestMapping("/viptypesearch")
    @ResponseBody
    public List<VipType> search() throws Exception{
        return vipTypeDao.getAll();
    }
    @RequestMapping("/updatevip")
    @ResponseBody
    public Map<String,Object> updatevip(Vip vip) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.update(vip);
        return map;
    }
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Map<String,Object> batchDelete(Integer[] ids) throws Exception{
        Map<String,Object> map = new HashMap<>();
        vipDao.batchDelete(ids);
        map.put("result",true);
        return map;
    }
    @RequestMapping("/addvip")
    @ResponseBody
   public Map<String,Object> addvip(Vip vip) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.add(vip);
        return map;
    }
    @RequestMapping("/updatevipmoney")
    @ResponseBody
    public Map<String,Object> updatevipmoney(Vip vip) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.updatemoney(vip);
        return map;
    }
    @RequestMapping("/getmoney")
    @ResponseBody
    public VipType getmoney(Integer id) throws Exception{
        return  vipTypeDao.get(id);
    }
    @RequestMapping("/guashi")
    @ResponseBody
    public Map<String,Object> guashi(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.updateguashi(id);
        return map;
    }
    @RequestMapping("/buka")
    @ResponseBody
    public Map<String,Object> buka(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.updatebuka(id);
        return map;
    }
    @RequestMapping("/huanka")
    @ResponseBody
    public Map<String,Object> huanka(Vip vip) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.updatehuanka(vip);
        return map;
    }
    @RequestMapping("/tuika")
    @ResponseBody
    public Map<String,Object> tuika(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.updatetuika(id);
        return map;
    }
    @RequestMapping("/jilu")
    @ResponseBody
    public Map<String,Object> jilu(VipRecrd vipRecrd) throws Exception{
        Map<String,Object> map=new HashMap<>();
        viprecrdDao.add(vipRecrd);
        return map;
    }
    @RequestMapping("/delvip")
    @ResponseBody
    public Map<String,Object> delvip(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.delete(id);
        return map;
    }
    @RequestMapping("/getphone")
    @ResponseBody
    public Map<String,Object> getphone(String phone) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.getphone(phone);
        return map;
    }
    @RequestMapping("/getjifenphone")
    @ResponseBody
    public Vip getjifenphone(String phone) throws Exception{
        return  vipDao.getjifenphone(phone);
    }
    @RequestMapping("/isnotid")
    @ResponseBody
    public List<VipType> isnotid(Integer id) throws Exception{
        return vipTypeDao.isnotid(id);
    }

}
